package com.reyco1.medusa.display.container
{
	import flash.display.DisplayObject;
	import flash.events.Event;

	public class HBox extends Container
	{
		public static const TOP:int    = 1;
		public static const MIDDLE:int = 2;
		public static const BOTTOM:int = 3;
		public static const NONE:int   = 0;
		
		private var _alignMode:int = 0;
		
		public function HBox()
		{
			super();
		}

		override protected function build():void
		{
			var ypos:Number = 0;
			var xpos:Number = 0;
			var i:int = 0;
			var child:DisplayObject;
			_width = 0;
			_height = 0;
			
			for(i = 0; i<numChildren; i++)
			{
				child = getChildAt(i);
				child.y = ypos;
				child.x = xpos;
				xpos += child.width + gap;
				_width += child.width;
				_height = Math.max(_height, child.height);
			}
			
			for(i = 0; i<numChildren; i++)
			{
				child = getChildAt(i);
				
				switch(alignMode)
				{
					case 1:
						child.y = 0;
						break;
					
					case 2:
						child.y = _height * 0.5 - child.height * 0.5;
						break;
					
					case 3:
						child.y = _height - child.height;
						break;
				}
			}
			
			_width += gap * (numChildren - 1);
			
			dispatchEvent(new Event(Event.RESIZE));
		}
		
		public function get alignMode():int
		{
			return _alignMode;
		}
		
		public function set alignMode(value:int):void
		{
			_alignMode = value;
			invalidate();
		}
		
	}
}